package com.example.product_practices.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.product_practices.domain.QuestionBank;
import com.example.product_practices.service.IQuestionBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xin.altitude.cms.common.entity.AjaxResult;
import xin.altitude.cms.common.entity.PageEntity;

import java.util.Arrays;

@RestController
@CrossOrigin
@RequestMapping("/questionBank")
public class QuestionBankController {
    @Autowired
    private IQuestionBankService questionBankService;

    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity, QuestionBank questionBank) {
        return AjaxResult.success(questionBankService.page(pageEntity.toPage(), Wrappers.lambdaQuery(questionBank)));
    }

    @GetMapping("/list")
    public AjaxResult list(QuestionBank questionBank) {
        return AjaxResult.success(questionBankService.list(Wrappers.lambdaQuery(questionBank)));
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody QuestionBank questionBank) {
        return AjaxResult.success(questionBankService.save(questionBank));
    }

    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody QuestionBank questionBank) {
        return AjaxResult.success(questionBankService.updateById(questionBank));
    }

    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Integer[] ids) {
        return AjaxResult.success(questionBankService.removeByIds(Arrays.asList(ids)));
    }

    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(questionBankService.getById(id));
    }
}
